package com.isoft.dao.flightUpdate;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.isoft.entity.flightUpdate.FlightUpdateInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * @author LiuGaoMing
 * @version 1.0
 * @description:
 * @date 2024/6/30 16:22
 */
@Mapper
public interface FlightUpdateInfoDao extends BaseMapper<FlightUpdateInfo> {
//    查询所有航班的META_ID、APAT、APNO、APCD
    @Select("select META_ID,APAT,APNO,APCD from DFME_AIRL_ARPT")
    public List<FlightUpdateInfo> getFlightUpdateInfo();
// 新增分页查询方法
    @Select("SELECT * FROM (SELECT META_ID,APAT,APNO,APCD,STATU FROM DFME_AIRL_ARPT LIMIT #{offset}, #{pageSize}) AS subquery ORDER BY META_ID")
    public List<FlightUpdateInfo> getFlightUpdateInfoPaged(@Param("offset") int offset, @Param("pageSize") int pageSize);
// 查询总记录数
    @Select("SELECT COUNT(*) FROM DFME_AIRL_ARPT")
    Long getTotalFlightUpdateInfoCount();

//    通过META_ID查询APNO
    @Select("select APNO from DFME_AIRL_ARPT where META_ID=#{META_ID}")
    public Integer[] getAPNOByMETAID(Integer META_ID);


//    通过META_ID和APNO获取APCD
    @Select("select APCD from DFME_AIRL_ARPT where META_ID=#{META_ID} and APNO=#{APNO}")
    public String getAPCDByMETAIDAndAPNO(Integer META_ID,Integer APNO);

//    根据METAID查询
    @Select("select * from DFME_AIRL_ARPT where META_ID=#{META_ID}")
    public List<FlightUpdateInfo> getFlightUpdateInfoByMETAID(Integer META_ID);

//  修改始发站的信息，根据METAID和APNO=1
    @Update("update DFME_AIRL_ARPT set APAT=#{APAT},APCD=#{APCD},STATU=#{STATU} where META_ID=#{METAID} AND APNO = 1")
    public Boolean updateStart(FlightUpdateInfo flightUpdateInfo);
//  修改终点站的信息，根据METAID和APNO=2
    @Update("update DFME_AIRL_ARPT set APAT=#{APAT},APCD=#{APCD},STATU=#{STATU} where META_ID=#{METAID} AND APNO = 2")
    public Boolean updateEnd(FlightUpdateInfo flightUpdateInfo);
    //  修改终点站的信息，根据METAID和APNO=3
    @Update("update DFME_AIRL_ARPT set APAT=#{APAT},APCD=#{APCD},STATU=#{STATU} where META_ID=#{METAID} AND APNO = 3")
    public Boolean updateENDT(FlightUpdateInfo flightUpdateInfo);
//    根据META_ID插入经停站APNO=3
    @Insert("insert into DFME_AIRL_ARPT(META_ID,APAT,APNO,APCD,STATU) values(#{METAID},#{APAT},#{APNO},#{APCD},#{STATU})")
    public Boolean insertFlightUpdateInfo(FlightUpdateInfo flightUpdateInfo);

}
